import { error, log, warn } from "cc";
import { WanderCommon } from "./Defines";
import Singleton from "./Singleton";

enum LogType {
    Info = 1,
    Warn = 2,
    Error = 3
}

class LogMgr extends Singleton {

    public setMode(mode: string) {
        this.isReleaseMode = mode == WanderCommon.PublishType.Release;
    }

    public table(msg:any) {
        console.table(msg);
    }

    public start(desc = 'Time') {
        console.time(desc);
    }

    public end(desc = 'Time') {
        console.timeEnd(desc);
    }

    public group(groupName:string) {
        console.group(groupName);
    }

    public groupEnd() {
        console.groupEnd();
    }

    public e(...data:any[]) {
        this.print(LogType.Error, console.error || error, ...data);
    }

    public i(...data:any[]) {
        this.print(LogType.Error, console.log || log, ...data);
    }

    public w(...data:any[]) {
        this.print(LogType.Warn, console.warn || warn, ...data);
    }

    private print(type: LogType, _log:(...data:any[])=>void, ...data:any[]) {
        if (this.isReleaseMode && type <= LogType.Warn) return;
        _log(...data);
    }

///
    private isReleaseMode = false;
}

const Log = LogMgr.getInstance() as LogMgr
export default Log;